//
//  MinecraftViewHeaderCollectionViewCell.m
//  CommunitySupermarketProiect
//
//  Created by 吕惠卿 on 2017/11/3.
//  Copyright © 2017年 吕惠卿. All rights reserved.
//

#import "MinecraftViewHeaderCollectionViewCell.h"

@implementation MinecraftViewHeaderCollectionViewCell
-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
        
    }
    return self;
}
-(void)creatUI{
//    http://www.jb51.net/article/78113.htm 图片加蒙版
    _bgImg = [[UIImageView alloc]init];
    _bgImg.image = [UIImage imageNamed:@"我的头部背景"];
//    _bgImg.backgroundColor = [UIColor yellowColor];
    [self addSubview:_bgImg];
    [_bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    _headerImg = [[UIImageView alloc]init];
    _headerImg.clipsToBounds=YES;
    _headerImg.layer.borderColor = [UIColor whiteColor].CGColor;
    _headerImg.layer.borderWidth = 3;
    _headerImg.layer.cornerRadius = 40;
    _headerImg.image = [UIImage imageNamed:@"我的页头像1"];
    [_bgImg addSubview:_headerImg];
    [_headerImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(_bgImg.mas_bottom).with.offset(-15);
        make.left.equalTo(_bgImg.mas_left).with.offset(15);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(80);
    }];
    
    _goldbgImg = [[UIImageView alloc]init];
    _goldbgImg.image = [UIImage imageNamed:@"背景"];
    [_bgImg addSubview:_goldbgImg];
    [_goldbgImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bgImg.mas_right);
        make.centerY.mas_equalTo(_headerImg);
        make.width.mas_equalTo(WIDTH/2.5);
        make.height.mas_equalTo(40);
    }];
    UIImageView *img = [[UIImageView alloc]init];
    img.image = [UIImage imageNamed:@"我的金币账户右"];
    [_bgImg addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bgImg.mas_right).with.offset(-5);
        make.centerY.mas_equalTo(_headerImg);
        make.width.mas_equalTo(9);
        make.height.mas_equalTo(17);
    }];
    

    NSMutableAttributedString * attrubedStr = [[NSMutableAttributedString    alloc]initWithString:[NSString stringWithFormat:@"金币账户 558"]];
    NSTextAttachment * attach = [[NSTextAttachment alloc]init];
    attach.image = [UIImage imageNamed:@"我的金币"];
    //图片位置
    attach.bounds = CGRectMake(-2, -5, 20, 20);
    NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attach];
    //将图片放在第一位
    [attrubedStr insertAttributedString:string atIndex:0];
    _goldLab = [[UILabel alloc]init];
    _goldLab.textAlignment = NSTextAlignmentCenter;
    _goldLab.font = [UIFont systemFontOfSize:15.0];
    _goldLab.textColor = [UIColor colorWithRed:253.0/255.0 green:0/255.0 blue:0/255.0 alpha:1];
    _goldLab.attributedText = attrubedStr;
//    _goldLab.text = @"金币账户 558 >";
    [_goldbgImg addSubview:_goldLab];
    [_goldLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(img.mas_left);
        make.centerY.mas_equalTo(_goldbgImg);
        make.width.mas_equalTo(WIDTH/2.5-10);
        make.height.mas_equalTo(40);
    }];
    _nameLab = [[UILabel alloc]init];
    _nameLab.text = @"test";
    _nameLab.font = [UIFont systemFontOfSize:17.0];
    _nameLab.textColor = [UIColor whiteColor];
    [_bgImg addSubview:_nameLab];
    [_nameLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_goldbgImg);
        make.height.mas_equalTo(40);
        make.right.equalTo(_goldbgImg.mas_left).with.offset(-5);
        make.left.equalTo(_headerImg.mas_right).with.offset(5);
    }];
    
    _setBtn = [[UIButton alloc]init];
    [_setBtn setImage:[UIImage imageNamed:@"我的设置"] forState:UIControlStateNormal];
    [_bgImg addSubview:_setBtn];
    [_setBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bgImg.mas_right).with.offset(-15);
        make.top.equalTo(_bgImg.mas_top).with.offset(35);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
}
@end
